DELETE ratings

PUT ratings/_doc/1
{
 "rating":5
}
PUT ratings/_doc/2
{
 "rating":null
}

POST ratings/_search

// 正常情况这个聚合的出来的平均值肉眼来看应该2.5是吧, 而且hints的数量应该是2 , 但是结果平均值是5, hints是2
POST ratings/_search
{
  "size": 0,
  "aggs": {
    "avg": {
      "avg": {
        "field": "rating"
      }
    }
  }
}


// null_value 解决null的聚合的问题
DELETE ratings

PUT ratings
{
  "mappings": {
      "properties": {
        "rating": {
          "type": "float",
          "null_value": 0
        }
      }
    }
}


PUT ratings/_doc/1
{
    "rating": 5
}
PUT ratings/_doc/2
{
    "rating": null
}

POST ratings/_search

POST ratings/_search
{
    "size": 0,
    "aggs": {
        "avg": {
            "avg": {
                "field": "rating"
            }
        }
    }
}

// 这里搜索值为0的, 也能查出那篇为null的文档
POST ratings/_search
{
    "query": {
        "term": {
            "rating": {
                "value": 0
            }
        }
    }
}
